package com.supcon.exchangedata.service.syncData;

import com.supcon.exchangedata.pojo.entity.oracle.sync.*;
import com.supcon.exchangedata.repository.master.*;
import com.supcon.exchangedata.repository.slave1.*;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.criterion.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yangbin
 * @Date: 2023/02/28/11:19
 * @Description:
 */
@Service
@Slf4j
public class SyncService {
    @Resource
    private SlaveOneMonth1Repository slaveOneMonth1Repository;

    @Resource
    private SlaveOneMonth2Repository slaveOneMonth2Repository;

    @Resource
    private SlaveOneMonth3Repository slaveOneMonth3Repository;

    @Resource
    private SlaveOneMonth4Repository slaveOneMonth4Repository;

    @Resource
    private SlaveOneMonth5Repository slaveOneMonth5Repository;

    @Resource
    private SlaveOneMonth6Repository slaveOneMonth6Repository;

    @Resource
    private SlaveOneMonth7Repository slaveOneMonth7Repository;

    @Resource
    private SlaveOneMonth8Repository slaveOneMonth8Repository;

    @Resource
    private SlaveOneMonth9Repository slaveOneMonth9Repository;

    @Resource
    private SlaveOneMonth10Repository slaveOneMonth10Repository;


    @Resource
    private MasterMonth1Repository masterMonth1Repository;

    @Resource
    private MasterMonth2Repository masterMonth2Repository;

    @Resource
    private MasterMonth3Repository masterMonth3Repository;

    @Resource
    private MasterMonth4Repository masterMonth4Repository;

    @Resource
    private MasterMonth5Repository masterMonth5Repository;

    @Resource
    private MasterMonth6Repository masterMonth6Repository;

    @Resource
    private MasterMonth7Repository masterMonth7Repository;

    @Resource
    private MasterMonth8Repository masterMonth8Repository;

    @Resource
    private MasterMonth9Repository masterMonth9Repository;

    @Resource
    private MasterMonth10Repository masterMonth10Repository;


    @Transactional
    public void syncMonthReport() {
        Example example = Example.create(new CtMonthReportBase());
        List<CtMonthReportBase> all1 = slaveOneMonth1Repository.findAll();
        List<CtMonthReportCsjs> all2 = slaveOneMonth2Repository.findAll();
        List<CtMonthReportGj> all3 = slaveOneMonth3Repository.findAll();
        List<CtMonthReportHj> all4 = slaveOneMonth4Repository.findAll();
        List<CtMonthReportLq> all5 = slaveOneMonth5Repository.findAll();
        List<CtMonthReportRdjt> all6 = slaveOneMonth6Repository.findAll();
        List<CtMonthReportRq> all7 = slaveOneMonth7Repository.findAll();
        List<CtMonthReportSw> all8 = slaveOneMonth8Repository.findAll();
        List<CtMonthReportThird> all9 = slaveOneMonth9Repository.findAll();
        List<CtMonthReportYjy> all10 = slaveOneMonth10Repository.findAll();
        handleData(all1, "1");
        handleData(all2, "2");
        handleData(all3, "3");
        handleData(all4, "4");
        handleData(all5, "5");
        handleData(all6, "6");
        handleData(all7, "7");
        handleData(all8, "8");
        handleData(all9, "9");
        handleData(all10, "10");

    }

    @Transactional
    public void handleData(List dataList, String index) {
        if (!CollectionUtils.isEmpty(dataList)) {
            switch (index) {
                case "1":
                    masterMonth1Repository.saveAll(dataList);
                    break;
                case "2":
                    masterMonth2Repository.saveAll(dataList);
                    break;
                case "3":
                    masterMonth3Repository.saveAll(dataList);
                    break;
                case "4":
                    masterMonth4Repository.saveAll(dataList);
                    break;
                case "5":
                    masterMonth5Repository.saveAll(dataList);
                    break;
                case "6":
                    masterMonth6Repository.saveAll(dataList);
                    break;
                case "7":
                    masterMonth7Repository.saveAll(dataList);
                    break;
                case "8":
                    masterMonth8Repository.saveAll(dataList);
                    break;
                case "9":
                    masterMonth9Repository.saveAll(dataList);
                    break;
                case "10":
                    masterMonth10Repository.saveAll(dataList);
                    break;
            }
        }
    }

}
